import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-10-02
 * Time: 0:11
 */
//Fibonacci数列
public class Fibonacci {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = 0, b = 1,c = 1;
        int ret = 0;
        while(n > c){
            a=b;
            b=c;
            c=a+b;
            if(n > b && n < c) {
                ret = Math.min(n-b,c-n);
            }
        }

        System.out.print(ret);
    }
}
